package com.cardbaobao.cardbabyclient.widget.seekBar;

import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.AppCompatSeekBar;
import android.util.AttributeSet;
import android.widget.SeekBar;

public class BubbleSeekBar extends AppCompatSeekBar{
	private SeekBarChangedListener seekBarChangedListener;
	public void setSeekBarChangedListener(SeekBarChangedListener seekBarChangedListener){
		this.seekBarChangedListener=seekBarChangedListener;
	}
	public interface SeekBarChangedListener{
		void onStopTrackingTouch(SeekBar seekBar);
		void onStartTrackingTouch(SeekBar seekBar, Rect bounds);
		void onProgressChanged(SeekBar seekBar, Rect bounds,int progress,boolean fromUser);
	}
	private Drawable mThumbDrawable;
	
	public BubbleSeekBar(Context context) {
		this(context, null);
	}

	public BubbleSeekBar(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public BubbleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		setOnSeekBarChangeListener(mOnSeekBarChangeListener);
	}
	
    @Override
    public void setThumb(Drawable thumb) {
        super.setThumb(thumb);
        mThumbDrawable = thumb;
    }
	  
	private OnSeekBarChangeListener mOnSeekBarChangeListener = new OnSeekBarChangeListener() {
		
		@Override
		public void onStopTrackingTouch(SeekBar seekBar) {
//			mBubbleIndicator.hideIndicator();
			if(seekBarChangedListener!=null){
				seekBarChangedListener.onStopTrackingTouch(seekBar);
			}
		}
		
		@Override
		public void onStartTrackingTouch(SeekBar seekBar) {
//			mBubbleIndicator.showIndicator(seekBar, mThumbDrawable.getBounds());
			if(seekBarChangedListener!=null){
				seekBarChangedListener.onStartTrackingTouch(seekBar,mThumbDrawable.getBounds());
			}
		}
		
		@Override
		public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
			if(seekBarChangedListener!=null){
				seekBarChangedListener.onProgressChanged(seekBar,mThumbDrawable.getBounds(), progress,fromUser);
			}
//			if(fromUser)
//				mBubbleIndicator.moveIndicator(mThumbDrawable.getBounds(), progress);
		}
	};
}
